#include "WindowSDL_1_2.h"

#include <SDL.h>
#include <cassert>

const char CWindowSDL_1_2::DEFAULT_TITLE[] = "Default Title";

CWindowSDL_1_2::CWindowSDL_1_2( void ) : m_pWnd( NULL ), m_pTitle( NULL )
{
    //ctor
}

CWindowSDL_1_2::~CWindowSDL_1_2( void )
{
    //dtor
}

int CWindowSDL_1_2::Init( void )
{
    m_pWnd = SDL_CreateRGBSurface( SDL_SWSURFACE, DEFAULT_WIDTH, DEFAULT_HEIGHT, 32, 0, 0, 0, 0 );

    if( m_pWnd == NULL )
    {
        // an error has occurred, hanle with care
        return -1;
    }

    m_pTitle = SDL_strdup( DEFAULT_TITLE );

    return 0;
}

int CWindowSDL_1_2::Init( const char* title, const int height, const int width )
{
    m_pWnd = SDL_CreateRGBSurface( SDL_SWSURFACE, width, height, 32, 0, 0, 0, 0 );

    if( m_pWnd == NULL )
    {
        // an error has occurred handle with care
        return -1;
    }

    assert( title );

    m_pTitle = SDL_strdup( title );

    return 0;
}

int CWindowSDL_1_2::Process( void )
{
    return 0;
}

void CWindowSDL_1_2::Refresh( void )
{
}

void CWindowSDL_1_2::ShutDown( void )
{
    if( m_pTitle != NULL )
    {
        SDL_free( m_pTitle );
        m_pTitle = NULL;
    }

    if( m_pWnd != NULL )
    {
        SDL_FreeSurface( m_pWnd );
        m_pWnd = NULL;
    }
}
